{* $Id$ *}
{include_core file="admin/lib/header.html" title="{if $is_delete==0}回收{/if}掌柜门店展示"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">影院管理<span>影院门店管理</span></h2>
    <a href="{AnUrl('store/admin/movie_store?is_delete=1')}" class="btn btn-default btn-sm right">&lt; 返回掌柜门店列表</a>
  </div>

  <div class="search-form js_advancedForm">
    <form action="store/admin/movie_store" method="get" class="js_focusSearchForm">
      <input type="hidden" name="is_advenced" value="1">
      <input type="hidden" name="is_delete" value="{$is_delete}">
      <input type="hidden" name="status" value="{$status}">
      <p>
        <label for="" class="search-f-label">合伙人姓名：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[dealer_name]" value="{$search_filter.dealer_name}">
      </p>
      <p>
        <label for="" class="search-f-label">门店名称(前缀)：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[title]" value="{$search_filter.title}">
      </p>
      <p>
        <label for="" class="search-f-label">门店名称(后缀)：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[title_branch]" value="{$search_filter.title_branch}">
      </p>
      <p>
        <label for="" class="search-f-label">掌柜姓名：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[realname]" value="{$search_filter.realname}">
      </p>
      <p>
        <label for="" class="search-f-label">掌柜手机号：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[mobile]" value="{$search_filter.mobile}">
      </p>
      <p>
        <label for="" class="search-f-label">地区筛选：</label>
        <select name="search_filter[province_id]" class="js_provinceList" style="width:120px;">
          <option value="0" selected="selected">请选择省份</option>
        </select>
        <select name="search_filter[city_id]" class="js_cityList" style="width:120px;{if !$search_filter['city_id'] || $search_filter['city_id'] == '000000'}display:none;{/if}">
          <option value="0">请选择城市</option>
        </select>
        <select name="search_filter[district_id]" class="js_countyList" style="width:120px;{if !$search_filter['district_id'] || $search_filter['district_id'] == '000000'}display:none;{/if}">
          <option value="0">请选择区(县)</option>
        </select>
      </p>
      <p>
      <label for="" class="search-f-label">添加时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>

<!--start:列表-->
<div class="list-table-filters">
    <p>
        <span class="label label-info">按状态</span>
        <a href='{AnUrl("store/admin?{URLTracker::set("status", -1)}")}' {if URLTracker::val('status') == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        {foreach store_config::$status_arr as $k => $v}
        <a href='{AnUrl("store/admin?{URLTracker::set("status", $k)}")}' {if URLTracker::val('status') == $k} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
        {/foreach}
    </p>
    <p>
        <span class="label label-info">按类型</span>
        <a href='{AnUrl("store/admin/movie_store?{URLTracker::set("type", "100")}")}' {if URLTracker::val('type') == 100} class="label label-primary" {else} class="label label-default" {/if}>影院</a>
        <a href='{AnUrl("store/admin/movie_store?{URLTracker::set("type", "105")}")}' {if URLTracker::val('type') == 105} class="label label-primary" {else} class="label label-default" {/if}>私人影吧</a>
    </p>
    <!--{if URLTracker::val('type') == '100'}-->
    <!--<p>-->
    <!--<span class="label label-info">按影院</span>-->
    <!--<a href='{AnUrl("store/admin?{URLTracker::set("movie_type", -1)}")}' {if URLTracker::val('movie_type') == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>-->
    <!--<a href='{AnUrl("store/admin?{URLTracker::set("movie_type", 1)}")}' {if URLTracker::val('movie_type') == 1} class="label label-primary" {else} class="label label-default" {/if}>直营</a>-->
    <!--<a href='{AnUrl("store/admin?{URLTracker::set("movie_type", 2)}")}' {if URLTracker::val('movie_type') == 2} class="label label-primary" {else} class="label label-default" {/if}>加盟</a>-->
    <!--<a href='{AnUrl("store/admin?{URLTracker::set("movie_type", 3)}")}' {if URLTracker::val('movie_type') == 3} class="label label-primary" {else} class="label label-default" {/if}>私营</a>-->
    <!--</p>-->
    <!--{/if}-->
</div>
{include_core file="admin/lib/pager.html"}
  <table class="list-table">
    <thead><tr>
      <th style="min-width:60px;">店铺id</th>
      <th style="min-width:60px;">店铺头图</th>
      <th style="min-width:200px;">店铺信息</th>
      <th style="min-width:60px;" >{if $is_delete==0}回收{/if}掌柜门店类型</th>
      <th style="min-width:60px;">添加时间</th>
      <th style="min-width:60px;">{if $is_delete==0}回收{/if}掌柜门店状态</th>
      <th style="width:60px;">操作</th>
    </tr></thead>
    <tbody>
      {foreach $store_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          <!-- {if $status == 1}
            <td><input type="checkbox" class="listSelect"></td>
          {/if} -->
          <td>{$v.id}</td>
          <td>
              <a href="{if $v['cover']}{_image($v['cover'])}{else}{store_helper::cover($v['cover'])}{/if}" target="_blank"><img width="100" src="{if $v['cover']}{_image($v['cover'])}{else}{store_helper::cover($v['cover'])}{/if}" /></a>
          </td>
          <td>
          店铺名称：{$v.title}{$v.title_branch}<br/>
           店长手机号：{$v.mobile}<br/>
          合伙人：{$v.dealer_name}<br/>
          合伙人手机号：{$v.dealer_mobile}<br/>
          店铺地址：{$v.address}
          </td>
          <td>{$v.type_name}</td>
          <td>{time_format($v.add_time)}</td>
          <td>
          {if $v.status == 1}
            <span class="label label-warning">未审核</span>
            <!-- <a href="{AnUrl("store/admin/recover_store?id={$v.id}")}" class="btn btn-warning btn-xs"><i class="icon-trash icon-white"></i>未审核</a> -->
          {elseif $v.status == 2}
            <span class="label label-success">正常</span>
            <!-- <a href="javascript:void(0);" class="btn btn-success btn-xs"><i class="icon-trash icon-white"></i>正常</a> -->
          {else}
            <span class="label label-danger">撤店</span>
            <!-- <a href="javascript:void(0);" class="btn btn-danger btn-xs"><i class="icon-trash icon-white"></i>撤店</a> -->
          {/if}
          </td>
          <td>
          <a href="{AnUrl("store/admin/verify_store?id={$v.id}&status=2&is_delete=$is_delete&store_type=100")}" class="btn btn-primary btn-xs"><i class="icon-trash icon-white"></i>
          {if $v.is_delete}
            {if $v.status == 1}审核{else}掌柜门店详情{/if}{else}回收掌柜门店详情
          {/if}
          </a>
          {if $v.status == 3}
             <a href="{AnUrl("store/admin/recover_store?id={$v.id}&is_delete=$is_delete&store_type=100")}" class="btn btn-warning btn-xs"><i class="icon-trash icon-white"></i>恢复</a>
          {/if}
          <a href="{AnUrl("store/admin/get_store_device_list?id={$v.id}&is_delete=$is_delete&store_type=100")}" class="btn btn-warning btn-xs"><i class="icon-trash icon-white"></i>{if $is_delete==0}回收{/if}掌柜门店设备</a>
          <a href="{AnUrl("store/admin/get_store_device_record?id={$v.id}&is_delete=$is_delete&store_type=100")}" class="btn btn-info btn-xs"><i class="icon-trash icon-white"></i>设备绑定记录</a>
           {if $v.is_delete == 0}
           <a href="{AnUrl("store/admin/undelete_store?id={$v.id}&is_delete=$is_delete&store_type=100")}" class="btn btn-warning btn-xs changeStatus"><i class="icon-trash icon-white"></i>还原</a>
           {else}
           <a href="{AnUrl("store/admin/edit?id={$v.id}&is_delete=$is_delete&store_type=100")}" class="btn btn-success btn-xs"><i class="icon-trash icon-white"></i>编辑</a>
           <!-- <a href="{AnUrl("store/admin/delete_store?id={$v.id}&is_delete=$is_delete&store_type=100")}" class="btn btn-danger btn-xs js_deleteStore"><i class="icon-trash icon-white"></i>删除掌柜门店</a> -->
           {/if}
          </td>
        </tr>
      {foreachelse}
          <tr><td class="txtleft" colspan="6">暂无数据</td></tr>
      {/foreach}
    </tbody>
    {if $status == 1}
    <tfoot><tr><td><input type="checkbox" class="selectAll"></td><td colspan="6"><a href="{AnUrl("store/admin/delete")}" class="btn btn-danger btn-xs deleteAll">批量禁用</a></td></tr></tfoot>
    {/if}
  </table>
  <script type="text/javascript">
  
//初始化省份列表
  $.ajax({
    url : 'area/admin/ajax_get_provinces',
    type : 'get',
    dataType : 'json',
    success : function(province_list){
      for (var i in province_list) {
        var opt = $('<option value="'+province_list[i]['area_code']+'">'+province_list[i]['area']+'</option>');
        $('.js_provinceList').append(opt);
      }

      {if $area['province_info']}
        $('.js_provinceList').val("{$area['province_info']['area_code']}");
        //触发请求
        $('.js_provinceList').change();
      {/if}

      {if $area['city_info']}
        $('.js_provinceList').val("{$area.province_info.area_code}");
        $('.js_cityList').val("{$area.city_info.area_code}");
        $('.js_cityList').change();
        $('.js_countyList').val("{$area['county_info']['area_code']}");
      {/if}
    }
  });
  
  
  
  
  $(function(){
          $('.js_provinceList').change(function(){
            //获取值
            if($(this).val() !== '0'){
              var province = $(this).val();
              $('.js_cityList').slideDown();
              $('.js_cityList').val('0');
              $('.js_countyList').slideUp();
              $('.js_countyList').val('0');
            }else{
              $('.js_cityList').slideUp();
              $('.js_countyList').slideUp();
              $('.js_countyList').val('0');
              $('.js_cityList').val('0');
              return false;
            }
            $('.js_cityList').empty();
            $('.js_cityList').append('<option value="0">请选择城市</option>');
            $('.js_countyList').empty();
            $('.js_countyList').append('<option value="0">请选择区(县)</option>');

            //发送ajax
            $.ajax({
              url : 'area/admin/ajax_get_citys?province_code='+province,
              success : function(city_list){
                for (var i in city_list) {
                  var opt = $('<option value="'+city_list[i]['area_code']+'">'+city_list[i]['area']+'</option>');
                  $('.js_cityList').append(opt);
                }

                {if $area.city_info}
                  $('.js_cityList').val("{$area.city_info.area_code}");
                {/if}
              },
              type : 'get',
              dataType : 'json',
              async : false,
            });


          });
          //城市
          $('.js_cityList').change(function(){
            if ( $('.js_provinceList').val() === '0' || $('.js_cityList').val() === '0') {
              $('.js_countyList').slideUp();
              $('.js_countyList').val('0');
              return false;
            } else {
              $('.js_countyList').slideDown();
              $('.js_countyList').val('0');
            }

            $('.js_countyList').empty();
            $('.js_countyList').append('<option value="0">请选择区(县)</option>');

            //获取省份的key和值
            var province_code = $('.js_provinceList').val();
            var pro_text = $('.js_provinceList').text();

            //获取城市的值
            var city_code = $(this).val();

            //发送ajax
            $.ajax({
              url : 'area/admin/ajax_get_countys?province_code='+province_code+'&city_code='+city_code,
              type : 'get',
              dataType : 'json',
              success : function(county_list){
                for (var i in county_list) {
                  var opt = $('<option value="'+county_list[i]['area_code']+'">'+county_list[i]['area']+'</option>');
                  $('.js_countyList').append(opt);
                }

                {if $area['county_info']}
                  $('.js_countyList').slideDown();
                  $('.js_countyList').val("{$area['county_info']['area_code']}");
                {/if}
              }
            });
            
          });

      // 声明一个字段映射
      var field_mapping = new Array();
     
       field_mapping['id'] = '店铺id';
       field_mapping['user_name'] = '分店店长';
       field_mapping['owner_name'] = '总店店长';
     /* field_mapping['agency_name'] = '合伙人';
       field_mapping['marketing_name'] = '市场人员'; */
       field_mapping['type'] = '掌柜门店类型';
       field_mapping['store_title'] = '掌柜门店名称';
       field_mapping['cover'] = '门头图';
       field_mapping['store_order'] = '分店序号';
       field_mapping['address'] = '掌柜门店地址';
       field_mapping['score'] = '掌柜门店积分';
       field_mapping['level'] = '掌柜门店等级';
       field_mapping['sign_user_name'] = '签约人员';
       field_mapping['sign_user_mobile'] = '签约人员的手机号';
       field_mapping['sign_time'] = '签约时间';
       
       // 设备状态
       var device_status_arr = new Array();
       device_status_arr[0] = '出厂';
       device_status_arr[1] = '损坏';
       device_status_arr[2] = '正常';
       device_status_arr[3] = '停用';
       device_status_arr[404] = '暂无';
      
       
   // 将指定的元素设置为可视区域居中
      function center_format(obj){
          // 获取可是窗口的宽度
          var winWidth  = $(window).width();
          var winHeight = $(window).height();
          
          // 计算窗体本身的宽和高
          var objWidth = obj.width();
          var objHeight = obj.height();
          
          // 设置窗体的位置
          obj.css('position', 'fixed');
          // 计算left和top值
          var objLeft = (winWidth - objWidth)/2;
          // var objTop = (winHeight - objHeight)/3; // 如果除以2感觉不是垂直居中
          obj.css('left', objLeft+'px');
          obj.css('top', '20px');
          
      }
      
    // 高级搜索
    $('.js_advanced').click(function(e){
      e.preventDefault();
      var thisObj = $(this);
      var outBox  = thisObj.closest('form');
      if (thisObj.hasClass('js_isOpen')) {
        thisObj.removeClass('js_isOpen open');
        outBox.find('input').show();
        outBox.find('button').show();
        $('.js_advancedForm').hide();
      } else {
        thisObj.addClass('js_isOpen open');
        outBox.find('input').hide();
        outBox.find('button').hide();
        $('.js_advancedForm').show();
      }
    });
    
 // 查看掌柜门店设备信息
    $('.js_storeDevice').click(function(){
        // 获取此掌柜门店的id
        var url = $(this).attr('url');
        var th = $(this);
        // 发送ajax查询掌柜门店信息
        $.ajax({
            url : url,
            type : "get",
            dataType : 'json',
            error : function (res) {
                showMsg('暂无设备绑定记录!');
            },
            success : function(res){
        
                if (res != 'no') {
                    var infoList = res;
                    $('.float-bg').show();
                    var list = $('.js_secondDealerList').clone(true, true);
                    
                     list.find('.js_dealerTitle').html('设备信息');
                     var head = $('<tr><th style="width:200px;text-align:center;border:1px solid #ccc">设备类型</th><th style="width:200px;text-align:center;border:1px solid #ccc">设备序列号</th><th style="width:200px;text-align:center;border:1px solid #ccc">绑定状态</th></tr>');
                     list.find('.js_expressTable').append(head);
                     $('body').append(list);
                     list.find('.js_verifySuccess').hide();
          

                    // 设置弹窗的位置
                    center_format(list);
                    list.show();
                    
                    // 说明 存在掌柜门店信息
          
              var str = '<tr>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">一代保温箱</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList['old_machine']['device_no']+'</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+device_status_arr[infoList['old_machine']['status']]+'</td></tr><tr>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">二代保温箱</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList['machine']['device_no']+'</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+device_status_arr[infoList['machine']['status']]+'</td></tr><tr>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">广告机</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList['adbox']['device_no']+'</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+device_status_arr[infoList['adbox']['status']]+'</td>';
              str += '</tr>';
              var info = $(str);
              list.find('.js_expressTable').append(info);
          
                    
                    list.find('.js_closeDealerList').click(function(){
                        list.hide();
                        list.remove();
                        $('.float-bg').hide();
                    });
                    
                } else {
                    showMsg('此{if $is_delete==0}回收{/if}掌柜门店下暂无设备!');
                }
            }
        });
        
        return false;
    });
    
    
    
    
    
 // 查看掌柜门店设备绑定记录
    $('.js_storeDeviceRecord').click(function(){
        // 获取此掌柜门店的id
        var url = $(this).attr('url');
        var th = $(this);
        // 发送ajax查询掌柜门店信息
        $.ajax({
            url : url,
            type : "get",
            dataType : 'json',
            error : function (res) {
                showMsg('暂无设备绑定记录!');
            },
            success : function(res){

                if (res != 'no') {
                    var infoList = res;
                    $('.float-bg').show();
                    var list = $('.js_secondDealerList').clone(true, true);
                    
                     list.find('.js_dealerTitle').html('设备绑定记录');
                     var head = $('<tr><th style="width:200px;text-align:center;border:1px solid #ccc">设备类型</th><th style="width:200px;text-align:center;border:1px solid #ccc">设备序列号</th><th style="width:200px;text-align:center;border:1px solid #ccc">时间</th><th style="width:200px;text-align:center;border:1px solid #ccc">绑定状态</th></tr>');
                     list.find('.js_expressTable').append(head);
                     $('body').append(list);
                     list.find('.js_verifySuccess').hide();
          

                    // 设置弹窗的位置
                    center_format(list);
                    list.show();
                    
                    // 说明 存在掌柜门店信息
          for (var i in infoList) {
              var str = '<tr>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]['device_name']+'</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]['device_no']+'</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]['add_time']+'</td>';
                str += '<td style="width:200px;text-align:center;border:1px solid #ccc">'+device_status_arr[infoList[i]['status']]+'</td>';
              str += '</tr>';
              var info = $(str);
              list.find('.js_expressTable').append(info);
          }
                    
                    list.find('.js_closeDealerList').click(function(){
                        list.hide();
                        list.remove();
                        $('.float-bg').hide();
                    });
                    
                } else {
                    showMsg('暂无设备绑定记录!');
                }
            }
        });
        
        return false;
    });
 
 
    // 查看掌柜门店信息
    $('.js_verifyStore').click(function(){
        // 获取此掌柜门店的id
        var url = $(this).attr('url');
        var th = $(this);
        // 发送ajax查询掌柜门店信息
        $.ajax({
            url : url,
            type : "get",
            dataType : 'json',
            error : function (res) {
                showMsg('暂无{if $is_delete==0}回收{/if}掌柜门店信息!');
            },
            success : function(res){
                if (res != 'no') {
                    var infoList = res;
                    $('.float-bg').show();
                    var list = $('.js_secondDealerList').clone(true, true);
                    
                     // list.find('.js_dealerTitle').html('审核掌柜门店');
                     
          list.find('.js_verifySuccess').attr('href', '{AnUrl("store/admin/recover_store")}'+'?id='+infoList['id']);
          $('body').append(list);

                    // 设置弹窗的位置
                    center_format(list);
                    list.show();
                    
                    // 说明 存在掌柜门店信息
          for (var i in infoList) {
              var info = $('<tr><td style="width:200px;text-align:center;border:1px solid #ccc">'+field_mapping[i]+'</td><td style="width:200px;text-align:center;border:1px solid #ccc">'+infoList[i]+'</td></tr>');
              list.find('.js_expressTable').append(info);
          }
                    
                    list.find('.js_closeDealerList').click(function(){
                        list.hide();
                        list.remove();
                        $('.float-bg').hide();
                    });
                    
                } else {
                    alert('暂无{if $is_delete==0}回收{/if}掌柜门店信息!');
                }
            }
        });
        
        return false;
    });
 
    
    
 // 单个掌柜门店删除
    $(".js_deleteStore").live('click',function(e){
      e.preventDefault();
      e.stopPropagation();
      var selectId = $(this).closest("tr").attr("id").substring(8);
      var roleId = $(this).closest("tr").data("id");
      if (!selectId) {
        alert('请选择要操作记录');
      }
      
      var clickObj = $(this);
      var url = clickObj.attr("href");
      var cardListBox = clickObj.closest('.cardListBox');
      var lines = $(this).parent().attr('rowspan');
      showConfirm('确定要删除这家掌柜门店吗？', 1, function(){
        $.post(url, {  'id':selectId }, function(json){
          if (json.info != 'ok') {
            alert(json.info);
          } else {
            clickObj.closest("tr").fadeOut(function(){
              if (lines) {
                for (var i = 1; i < lines; i++) {
                  $(this).next().remove();
                }
              };
              $(this).remove();
              interLineColor();
              showMsg('删除成功!被删除掌柜门店可在回收站还原.', 1);
              if (cardListBox) {
                var trNum = cardListBox.find('.deleteOne').length;
                var level_total = cardListBox.attr('data-level_total');
                consoleLog(trNum);
                consoleLog(level_total);
                if (trNum < level_total) {
                  $('.addCard').show();
                }
              }
              
              
            });
          }
        }, 'json');
      });
      return false;
    });

 
 
 
 
 

  });
  </script>
<div class="float-confirm js_secondDealerList" style="z-index: 20000;display: none; width:auto; height:auto; margin:0px; position : fixed;">
  <div class="float-confirm-con" style="margin:0px 0px; overflow:scroll;">
    <a class="icon-close js_closeDealerList" href="javascript:void(0);">关闭</a>
    <p style="font-size:18px;color:#23a18b;" class="js_dealerTitle">{if $is_delete==0}回收{/if}掌柜门店审核</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;max-height:400px;over-flow:hidden;margin-bottom:15px;">
      <table style="line-height:50px;border:1px solid #ccc;margin:0 auto;" class="js_expressTable">
        <!-- <tr>
          <th style="width:200px;text-align:center;border:1px solid #ccc">用户名</th>
          <th style="width:200px;text-align:center;border:1px solid #ccc">手机号码</th>
        </tr> -->
        
      </table>
      <table style="line-height:50px;width:100%;line-height:24px;margin:0 auto; padding-left:20px;" class="js_refundTable">
        <tr>
          <td rolspan="2" style="text-align:center; padding-right:20px;" ><a href="javascript:;" class="btn btn-success right js_verifySuccess" style="width:50%;;margin:20px auto;"><i class="icon-trash icon-white"></i>审核通过</a></td>
        </tr>
      </table>
    </div>
  </div>
</div>
<div class="float-bg" style="z-index: 19999; display: none"></div>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
{include_core file="admin/lib/footer.html"}